<?php
class Default_Model_MenuTour extends Zend_Db_Table {
	protected $_name    = 'menu_tour';
	protected $_primary = 'id';
	
	protected $_referenceMap = array(
			'Menu'=>array(
					'columns' => array('sub_menu_id'),
					'refTableClass' => 'Default_Model_SubMenu',
					'refColumns' => array('id'),
					'onDelete' => self::CASCADE,
			),
			'Category'=>array(
					'columns' => array('tour_category_id'),
					'refTableClass' => 'Default_Model_TourCategory',
					'refColumns' => array('id'),
					'onDelete' => self::CASCADE,
			)
	
	);
	
	// save item
	public function saveItem($arrParam = null, $options = null) {
		if($options['task'] == 'admin-add') {
	   		$row = $this->fetchNew();
	   		$row->tour_category_id = $arrParam['category_id'];
	   		$row->sub_menu_id      = $arrParam['menu'];

	   		$row->save();
	   	}
	   	
	   	if($options['task'] == 'admin-edit'){
	   		$id    = $arrParam['id'];
	   		$where = 'tour_category_id = ' . $id;
	   		$row   = $this->fetchRow($where);
	   		if(empty($row)){
	   			$row = $this->fetchNew();
	   			$row->tour_category_id = $arrParam['id'];
	   		}
	   		
	   		$row->sub_menu_id = $arrParam['menu'];
	   		
	   		$row->save();
	   		
	   	}
	}
	
	// delete item
	public function deleteItem($arrParam = null, $options = null) {
		if($options['task'] == 'admin-delete-category'){
			$id = $arrParam['id'];
			$where = 'tour_category_id = ' . $id;
		    $this->delete($where);
		}
	}
}